﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WarehouseWebAPP.code.DAL.CustomerDSTableAdapters;
using WarehouseWebAPP.code.DAL;

namespace WarehouseWebAPP.code.BLL
{
    public class CustomerBLL
    {
        private customerTableAdapter CustomerAdapter = null;
        public customerTableAdapter Adapter
        {
            get
            {
                if (CustomerAdapter == null) CustomerAdapter = new customerTableAdapter();
                return CustomerAdapter;
            }
        }

        public CustomerDS.customerDataTable CustomerGet()
        {
            return Adapter.GetData();

        }


        public void CustomerInsert(string customer_id, string customer_name, string customer_type, string customer_address, string customer_phone, string customer_email)
        {
           
            if (customer_name == null)
                throw new Exception("Customer Name is missing");

            if (Adapter.CustomerInsert(customer_id, customer_name, new Guid(customer_type), customer_address, customer_phone, customer_email) < 1)
                throw new Exception("No Customer was added");
        }

        public void CustomerUpdate(string customer_id, string customer_name, Guid customer_type, string customer_address, string customer_phone, string customer_email, Guid customer_num)
        {

            if (customer_num == null)
                throw new Exception("Customer Num is missing");

            if (Adapter.CustomerUpdate(customer_id, customer_name, customer_type, customer_address, customer_phone, customer_email,customer_num) < 1)
                throw new Exception ("No Customer was apdated");
        }
        public void CustomerDelete(Guid customer_num)
        {
            if (Adapter.CustomerDelete(customer_num) < 1)
                throw new Exception("No Customer was deleted");
        }

        public CustomerDS.customerDataTable CustomerGetByEmail(string customer_email)
        {
            if (customer_email == null)
                throw new Exception("Customer E-mail is missing");
            return Adapter.CustomerGetByEmail(customer_email);
        }

        public CustomerDS.customerDataTable CustomerGetById(string customer_id)
        {
            if (customer_id == null)
                throw new Exception("Customer ID is missing");
           
            return Adapter.CustomerGetByID(customer_id);
        }

        public CustomerDS.customerDataTable CustomerGetByNum(Guid customer_num)
        {
            if (customer_num == null)
                throw new Exception("Customer Num is missing");

            return Adapter.CustomerGetByNum(customer_num);
        }

        public CustomerDS.customerDataTable CustomerGetByType(Guid customer_type)
        {
            if (customer_type == null)
                throw new Exception("Customer Type is missing");

            return Adapter.CustomerGetByType(customer_type);
        }

        public CustomerDS.customerDataTable CustomerGetByName(string customer_name)
        {
            if (customer_name == null)
                throw new Exception("Customer name is missing");
            return Adapter.GetDataByName(customer_name);
        }

        public CustomerDS.customerDataTable CustomerSearch(string customer_id,string customer_name, string customer_address, string customer_email,string customer_type)
        {
            return Adapter.CustomerSearch(customer_id, customer_email, customer_name, customer_address, customer_type);
        }

    }
    
}
